package com.hgsoft.pubsv.component.base.context;

import com.hgsoft.pubsv.component.base.dto.BaseApiReqDto;

import cn.hutool.core.thread.threadlocal.NamedInheritableThreadLocal;

/**
 * 接口token上下文
 * 
 * @author saint
 *
 */
public abstract class ApiReqContextHolder {

	private static final ThreadLocal<BaseApiReqDto> requestAuthAttributesHolder = new NamedInheritableThreadLocal<>(
			"api Request");

	/**
	 * 删除
	 */
	public static void resetBaseApiReqDto() {
		requestAuthAttributesHolder.remove();
	}

	/**
	 * 设置
	 *
	 * @param authorized
	 */
	public static void setBaseApiReqDto(BaseApiReqDto apiReqDto) {
		requestAuthAttributesHolder.set(apiReqDto);
	}

	/**
	 * 获取
	 *
	 * @return
	 */
	public static BaseApiReqDto getBaseApiReqDto() {
		return requestAuthAttributesHolder.get();
	}
	
	public static String getClientKey() {
		BaseApiReqDto dto = getBaseApiReqDto();
		return  dto!=null? dto.getClientKey():"";
	}

	public static String getAccessNo() {
		BaseApiReqDto dto = getBaseApiReqDto();
		return  dto!=null? dto.getAccessNo():"";
	}
}
